package org.example.payment.controller;


import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import org.example.common.Response;
import org.example.payment.PaymentCountMapper;
import org.example.payment.entity.PaymentCountDO;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

/**
 * 支付金额控制层
 */
@RequestMapping("/api/paymentCount")
@RestController
public class PaymentCountController {

    @Resource
    private PaymentCountMapper paymentCountMapper;

    /**
     * 获取支付金额(单位元 两位小数）
     * @return
     */
    @GetMapping("/get")
    public Response<Float> getPaymentCount() {
        PaymentCountDO paymentCountDO = paymentCountMapper.selectOne(new LambdaQueryWrapper<PaymentCountDO>()
                .eq(PaymentCountDO::getId, 1));

        return Response.success(paymentCountDO.getCount());
    }

    /**
     * 修改支付金额
     * @param count 修改后的支付金额(单位元 两位小数)
     * @return
     */
    @PostMapping("/update")
    public Response<Boolean> update(Float count) {
        PaymentCountDO paymentCountDO = paymentCountMapper.selectOne(new LambdaQueryWrapper<PaymentCountDO>()
                .eq(PaymentCountDO::getId, 1));
        paymentCountDO.setCount(count);
        boolean update = paymentCountMapper.updateById(paymentCountDO) > 0;
        return Response.success(update);
    }

}
